package AnnualIncome;

import org.apache.hadoop.io.FloatWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

// map阶段
// KEYIN: 输入数据的key的类型
// VALUEIN: 输入数据的value的类型
// KEYOUT: 输出数据的key的类型
// VALUEOUT: 输出数据的value的类型
public class AnnualIncomeMapper extends Mapper<LongWritable, Text, FloatWritable, IntWritable> {
    private final static IntWritable valutOut = new IntWritable(1);
    private Text keyOut = new Text();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        String line = value.toString();

        String[] words = line.split(",");

        String EL = String.valueOf(words[10]);

        float num = new Float(EL);

        if(num<=30000){
            num = 1;
        }else if(num>30000&&num<=60000){
            num = 2;
        }else if(num>60000&&num<=90000){
            num = 3;
        }else if(num>90000&&num<=120000){
            num = 4;
        }else {
            num = 5;
        }

        context.write(new FloatWritable(num), valutOut);

    }
}
